package service

import (
	"RestaurantApp/dao"
	"RestaurantApp/model"
	"RestaurantApp/param"
	"RestaurantApp/utils"
	"github.com/wonderivan/logger"
)

type MemberService struct {
}

func (this *MemberService) LoginByPassword(loginParam param.LoginParam) model.Member {
	username := loginParam.Name
	password := loginParam.Password
	logger.Info("接收到的参数: ", username, "  ", password)
	password = utils.EncoderSha256(password)

	memberDao := dao.MemberDao{}
	member := memberDao.QueryMemberByUsernameAndPassword(username, password)

	if member.Id == 0 {
		return memberDao.AddMemberByUsernameAndPassword(username, password)
	} else {

		return member

	}

}

func (this *MemberService) GetUserInfoByUserId(userId int) model.Member {
	memberDao := dao.MemberDao{}
	return memberDao.GetUserInfoByUserId(userId)
}
